//解析硬件上报的数据
export function parseData(originalData){
	//声明返回数据数组
	let retDataArr={};
	let newData=originalData;
	let dataArr=newData.split(" ");
	//先解析命令符
	let cmd=dataArr[2];
	if(cmd==81){
		//说明是硬件定时上报数据
		let leftRightPower=dataArr[3];
		let convertLeftRightPower=parseInt(leftRightPower,16);
		retDataArr['convertLeftRightPower']=convertLeftRightPower;
		let leftAfterPower=dataArr[4];
		let convertLeftAfterPower=parseInt(leftAfterPower,16);
		retDataArr['convertLeftAfterPower']=convertLeftAfterPower;
		//取7和8,低位和高位
		let dividendNum=1;//被除数
		for(let i=7;i<15;i++){
			if(i%2==0){
				//说明是偶数，跳过
				continue;
			}
			dividendNum++;
			let hightOneL=dataArr[i];
			let hightOneH=dataArr[i+1];
			let strHightOne=hightOneH+''+hightOneL;
			let intHightOne=parseInt(strHightOne,16);
			let convertHigntOne=(intHightOne/10);
			let convertHigntOneName='height'+(dividendNum-1);
			retDataArr[''+convertHigntOneName+'']=parseFloat(convertHigntOne.toFixed(1));
		}
		//取DATA[12]，取数组第15位
		let advanceEnabled=dataArr[15];
		let advanceEnabled16=parseInt(advanceEnabled,16);
		let convertAdvanceEnabled=advanceEnabled16.toString(2);
		while (convertAdvanceEnabled.length < 4) {
			convertAdvanceEnabled = '0' + convertAdvanceEnabled;
		}
		//反转字符串，因为bit位从右到左开始
		let revertVal=convertAdvanceEnabled.split('').reverse().join('');
		let revertArr=revertVal.split('');
		//bit0：路况自适应，bit1：车速自适应，bit2：防侧倾，bit3：刹车防点头
		let itemName=['roadStaus','speedStatus','antiRoll','breakNode']
		for(let k=0;k<itemName.length;k++){
			let itemKey=itemName[k]
			let itemVal=revertArr[k];
			let itemStatus=false;
			if(itemVal==1){
				itemStatus=true;
			}
			retDataArr[''+itemKey+'']=itemStatus;
		}
		//跳过DATA[13]，跳过，数组第15位
		//取DATA[14]，取数组第16位,当前减震模式（0：舒适，1：运动，2：高速）
		let shockMode=dataArr[17];
		let convertShockMode=parseInt(shockMode,16);
		retDataArr['convertShockMode']=convertShockMode;
		//DATA[15]，取数组第17位
		let seventeenHex=dataArr[18];
		let seventeenHexVal=parseInt(seventeenHex,16);
		let convertSeventeenHexVal=seventeenHexVal.toString(2);
		while (convertSeventeenHexVal.length < 4) {
			convertSeventeenHexVal = '0' + convertSeventeenHexVal;
		}
		//反转字符串，因为bit位从右到左开始
		let revertSeventeenVal=convertSeventeenHexVal.split('').reverse().join('');
		let revertSeventeenArr=revertSeventeenVal.split('');
		//高度传感器控制（0：正接，1：反接； bit0：左前，bit1：右前，bit2：左后，bit3：右后）
		let itemSeventeenName=['leftBefore','rightBefore','leftAfter','rigthAfter']
		for(let j=0;j<itemSeventeenName.length;j++){
			let itemSeventeenKey=itemSeventeenName[j]
			let itemSeventeenVal=revertSeventeenArr[j];
			let itemSeventeenStatus='';
			if(itemSeventeenVal==0){
				itemSeventeenStatus='正接';
			}else{
				itemSeventeenStatus='反接';
			}
			retDataArr[''+itemSeventeenKey+'']=itemSeventeenStatus;
		}
	}
	return retDataArr;
}
